$(document).ready(function () {
    allArticle();
});


function addHtmlCode(obj) {
    console.log(obj);
    $('#source').find('.article_title').html(obj.article_title);
    $('#source').find('.article_title').attr("href","single.html?id="+obj.article_id);
    $('#source').find('img').attr("src","https://picsum.photos/358/238/?random");
    $('#source').find('span').html(obj.article_create_at);
    var htmlCode = $('#source').html();
    $("#mainCode").append(htmlCode);
}





function allArticle() {
    $.ajax({
        url:"http://123.207.241.214/api/getAll",
        type:"POST",
        async:true,
        data:{},
        timeout:5000,
        dataType:'json',
        success:function (data) {

            if (data['code']==0){
                alert("请重试");
            }else {
                for (var i in data['data']){
                    addHtmlCode(data['data'][i]);
                }
            }
        },
        error:function () {
            console.log("失败");
        }
    })
}


